from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get('https://www.baidu.com')
# 标签加属性
# search_box_id = driver.find_element(By.CSS_SELECTOR,'#kw')
# search_box_class = driver.find_element(By.CSS_SELECTOR,'.s_ipt')
# search_box_name = driver.find_element(By.CSS_SELECTOR,'input[name="wd"]')
# print(search_box_id.get_attribute('outerHTML'))
# print(search_box_class.get_attribute('outerHTML'))
# print(search_box_name.get_attribute('outerHTML'))
# 索引
span_element = driver.find_element(By.CSS_SELECTOR,'form[id="form"] :nth-child(9)')
print(span_element.get_attribute('outerHTML'))
input_element_8 = driver.find_element(By.CSS_SELECTOR,'form[id="form"] input:nth-of-type(8)')
print(input_element_8.get_attribute('outerHTML'))
time.sleep(120)
# input_element = driver.find_element(By.CSS_SELECTOR,'form[id="form"] input')
# print(input_element.get_attribute('outerHTML'))
# #模糊匹配
# element_1 =driver.find_element(By.CSS_SELECTOR,'input[name*="_idx"]')
# print(element_1.get_attribute('outerHTML'))
#
# # 多条件查找
# element_2 = driver.find_element(By.CSS_SELECTOR,'input[name="wd"][autocoplete="off"]')
# print(element_2.get_attribute('outerHTML'))

time.sleep(3)
driver.quit()